package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachPlanDto;
import com.xuecheng.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "课程计划管理接口")
@Slf4j
public class TeachPlanController {


    @Autowired
    private TeachPlanService teachPlanService;
    /**
     * 查询课程计划
     * @param courseId
     * @return
     */
    @ApiOperation("查询课程计划树形结构")
    @GetMapping("teachplan/{courseId}/tree-nodes")
    public List<TeachPlanDto> getTeachPlanTree(@PathVariable Long courseId){
        return teachPlanService.getTeachPlanTree(courseId);
    }

    /**
     * 新增/修改课程计划
     * @param saveTeachplanDto
     */
    @ApiOperation("新增/修改课程计划")
    @PostMapping("teachplan")
    public void saveTeachplan(@RequestBody  SaveTeachplanDto saveTeachplanDto){
            teachPlanService.saveTeachplan(saveTeachplanDto);
    }

    /**
     * 删除课程计划
     */
    @ApiOperation("删除课程计划")
    @DeleteMapping("teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id){
        teachPlanService.deleteTeachplan(id);
    }

    /***
     * 课程上移
     * @param id
     */
    @ApiOperation("课程计划上移")
    @PostMapping("teachplan/moveup/{id}")
    public void moveup(@PathVariable Long id){
        teachPlanService.moveup(id);
    }

    /**
     * 课程计划下移
     * @param id
     */
    @ApiOperation("课程计划下移")
    @PostMapping("teachplan/movedown/{id}")
    public void movedown(@PathVariable Long id){
        teachPlanService.movedown(id);
    }

    /**
     * 课程计划与媒资文件的绑定
     * @param bindTeachplanMediaDto 课程计划与媒资文件的绑定信息
     */
    @ApiOperation("课程添加媒资视频")
    @PostMapping("teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation("删除关联的媒资视频")
    @DeleteMapping("teachplan/association/media/{teachplanId}/{mediaId}")
    public void deleteAssociationMedia(@PathVariable Long teachplanId,@PathVariable String mediaId){
        teachPlanService.deleteAssociationMedia(teachplanId,mediaId);
    }
}
